package com.feynman.pattern.singleton.lazy;

/**
 * @ClassName LazyDoubleCheckSingleton
 * @Description 双检查锁单例
 * @Author Feynman
 * @date 2019/4/4 20:21
 * @Version V1.0
 **/
public class LazyDoubleCheckSingleton {

    //防止CPU指令重排序问题加volatile修饰
    private volatile static LazyDoubleCheckSingleton lazy = null;

    private LazyDoubleCheckSingleton(){

    }

    //双重检查锁结构
    public static LazyDoubleCheckSingleton getInstance(){
        if(lazy == null){
            synchronized (LazyDoubleCheckSingleton.class){
                if(lazy == null){
                    lazy = new LazyDoubleCheckSingleton();
                }
            }
        }
        return lazy;
    }
}
